home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / addToLayeredTx.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  2.7 KB  |  86 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Procedure: addToLayeredTx
  19. //
  20. // Description:
  21. //
  22. //        Add a file texture to a layered texture node.
  23. //        If $layeredTx is specified as an empty string
  24. //        than a new layered texture node is created.
  25. //
  26. // Arguments:
  27. //        layeredTx : layered texture to add to
  28. //        newTexture : texture to add
  29. //        killColorLayer : if the right-most layer is a color, replace it.
  30. //        connectAlpha : connect textures alpha up to the layered texture alpha
  31. //
  32. // Author : Bernard Kwok
  33. // Last Updated : 07/18/00
  34. //
  35. global proc 
  36. string addToLayeredTx(string $layeredTx, string $newTexture, 
  37.                       int $blendMode,
  38.                       int $killColorLayer, int $connectAlpha)
  39. {
  40.     if (size($newTexture) == 0)
  41.         error ("No texture name passed to addFileToLayeredTx()");
  42.  
  43.     // Create a new layered texture if none
  44.     if (size($layeredTx) == 0)
  45.         $layeredTx = `shadingNode -asTexture layeredTexture`;
  46.     
  47.     int $idx = `getAttr -s ($layeredTx+".inputs")`;
  48.  
  49.     // If layer to connect to has no input, than overwrite it
  50.     if ($killColorLayer && ($idx > 0))
  51.     {
  52.         int $idx1 = $idx - 1;
  53.         string $connected[] = `listConnections -s 1 ($layeredTx+".inputs["+$idx1+"].color")`;
  54.         if (size($connected) == 0)
  55.             $idx = $idx - 1;
  56.     }
  57.     // Just in case something weird happens...
  58.     if ($idx < 0) $idx = 0;
  59.  
  60.     // Hook up the file texture to the layered texture
  61.     while (catch(
  62.         `connectAttr ($newTexture+".outColor") ($layeredTx+".inputs["+$idx+"].color")`))
  63.     {
  64.         $idx = $idx + 1;
  65.     }
  66.  
  67.     if ($connectAlpha)
  68.     {
  69.         while (catch (`connectAttr ($newTexture+".outAlpha") ($layeredTx+".inputs["+$idx+"].alpha")`))
  70.         {
  71.             $idx = $idx + 1;
  72.         }
  73.     }
  74.     //print ("Final index used = " + $idx + "\n");
  75.     
  76.     // Set the blend mode. Leave it at none, if its the first texture
  77.     if ($idx != 0)
  78.     {
  79.         setAttr ($layeredTx + ".inputs[" + $idx + "].blendMode ")  $blendMode;
  80.     }
  81.     
  82.     return $layeredTx;
  83. }
  84.  
  85.  
  86.